<template>
	<view>
		<u-popup v-model="popShowFlag" mode="bottom" border-radius="14"
				 :height="(innerWindowHeight)+'px'" :mask-close-able="false">
				 <view style="padding-top: 10%;">
					 <view class="u-p-30 u-flex u-row-between u-col-center u-border-bottom">
						<view  @click="closePopUp()">
							<u-icon name="close" size="34"></u-icon>
						</view> 
						 <view style="font-size: 34rpx;font-weight: bold;">{{innerRecordTitle}}</view>
						 <!-- @click="saveShareMsg"-->
						 <view> 
							<!-- <u-icon  name="more-dot-fill" color="#606266" size="40"></u-icon> -->
						 </view>
					 </view>
					<scroll-view v-if="contentList.length>0"
								 :scroll-y="true" class="hidden-scroll-bar" 
								 :style="'height:'+scrollViewHeight+'px'">
						<view v-for="(msgItem,index) in contentList" :key="index">
							<inner-chat-item :chatGroupType="1" :showCheck="false"  :item="msgItem"  :previewSrcArr="previewSrcArr"></inner-chat-item>
						</view>
					</scroll-view>
				</view>	
		</u-popup>
	</view>
</template>

<script>
	import innerChatItem from '@/components/chat-item/inner-chat-item.vue';
	export default {
	    components:{
			innerChatItem
		},
		props:{
			innerRecordTitle:'',
			contentObjStr:{
				type: String,
				default:'',
			}
		},
		data() {
			return {
				contentList:[],	 //信息记录
				scrollViewHeight:0,
				popShowFlag:false,
				innerWindowHeight:0,
				headerHeight:0,
				saveObj:'',
				previewSrcArr:[],
			};
		},
		mounted:function(option){
			let that=this;
			let pageHeight= this.$u.sys().windowHeight;
			this.innerWindowHeight =pageHeight;
			this.scrollViewHeight =pageHeight * 0.88;
			if(this.contentObjStr.length>0){
				let contentObj=JSON.parse(this.contentObjStr);
				let contentStr= contentObj.content;
				let contentList= JSON.parse(contentStr);
				this.contentList=contentList;
				this.popShowFlag=true;
				console.log("contentList",this.contentList);
				this.contentList.sort(function(x,y){
					if(x.id<y.id){
						return -1;
					}else{
						return 1;
					}
				});
				this.contentList.map(function(item){
				   if(item.contentType==2||item.contentType==11){
					   let imageObj=JSON.parse(item.content);
					   let src=imageObj.url;
					   that.previewSrcArr.push(src);
				   }
				})
			}
		},

		methods:{
			//解析分享内容
			parseChatRecord: function(content) {
				let userName = content.userName;
				let contentType = content.contentType;
				let innerContent = content.content;
				let str = userName + ": [不可识别的信息类型]";
				switch (contentType) {
					case 1:
						let text = JSON.parse(innerContent).text;
						text = text.replace(/face/g, '');
						str = userName + ": " + text;
						break;
					case 2:
						str = userName + ": [图片]";
						break;
					case 3:
						str = userName + ": [视频]";
						break;
					case 4:
						str = userName + ": [语音]";
						break;
					case 5:
						str = userName + ": [文件]";
						break;
					case 7:
						str = userName + ": [红包]";
						break;
					case 8:
						str = userName + ": [名片]";
					case 9:
						str = userName + ": [位置]";
						break;
					case 10:
						str = userName + ": [聊天记录]";
						break;
					case 11:
						str=userName+": [图文信息]";
						break;
					case 12:
						str=userName+": [视频文字混合]";
						break;		
					default:
						break;
				}
				return str;
			},
			closePopUp:function(){
				console.log("关闭")
				this.popShowFlag=false;
				this.$emit("closeRecordPop",false);
			},
			
			//保存分享的记录
			saveShareMsg:function(item){
				let that = this;
				let navbarTitle = this.parseChatRecordTitle(item);
				//let viewRecordFlag=that.currentChatGroup.shareMsgFlag;
				//let masterFlag= that.currentChatGroup.memberType;
				let viewRecordFlag=1;
				let masterFlag=0;
				let forceShareFlag=0;
				if(viewRecordFlag==1&&masterFlag==0){
					forceShareFlag=1;
				}
				that.$u.route({
					url: '/pages/chat/chat-record-content',
					params: {
						chatRecordContentObj: encodeURIComponent(JSON.stringify(item)),
						navbarTitle: navbarTitle,
						forceShareFlag:forceShareFlag,
					},
					animationType: 'slide-in-bottom'
				})
			},
			parseChatRecordTitle: function(item) {
				let title = "聊天记录";
				let titleSet = new Set();
				let obj = JSON.parse(item.content);
				for (let i = 0; i < obj.length; i++) {
					let userName = obj[i].userName;
					titleSet.add(userName);
				}
				let userNames = Array.from(titleSet);
				if (userNames.length < 3) {
					return userNames.join("与") + "的聊天记录";
				} else {
					return title;
				}
			},			
			
		}
	}
</script>

<style lang="scss" scoped>

</style>
<style>
	page {
		background-color: #f1f1f1;
	}
</style>
